package threadcoreknowledge.createthread.threadobjectclasscommommethods;

public class Join {

    public static void main(String[] args) throws InterruptedException {


        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"运行完毕");
            }
        });

        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"运行完毕");
            }
        });

        thread1.start();
        thread2.start();

        System.out.println("开始等待子线程运行完毕");

        //使用join可以让主线程等待子线程执行完毕
//        thread1.join();
//        thread1.join();

        System.out.println("所有子线程执行完毕");
    }

}
